<?php
require_once("DBFunctions.php");

class GetCredentials {
	
	function getEmail() {
		session_start();
		if (isset($_SESSION['email']) && !empty($_SESSION['email']) && $_SERVER['REMOTE_ADDR'] == $_SESSION['ip']) {
			return ($_SESSION['email']);
		} else {
			die("Could not get email");;
		}
	}
	
	function getUserID() {
		$email = $this->getEmail();
		$uid = "";
		$db = new DBFunctions;
		$db->connectDB();
		$query = "call getUserID('".$email."',@a);";
		$result = $db->query($query);
		if (!$result || mysqli_num_rows($result) != 1) {
			die("Failed stored procedure call (getUserID)" );
		} else {
			while( $line = mysqli_fetch_array( $result, MYSQL_ASSOC ) ) {
				$uid = $line['User_ID'];
			}
		}
		$db->closeDB();
		if ($uid) {
			return $uid;
		} else {
			die("Could not get user ID");
		}
	}

}

?>